# 论坛发帖
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

url = r'http://192.168.183.140/upload/'
driver = webdriver.Chrome(options=options)
driver.get(url)
# 窗口最大化
driver.maximize_window()

# 登录
driver.find_element(By.ID, 'ls_username').clear()
driver.find_element(By.ID, 'ls_username').send_keys('admin')
driver.find_element(By.ID, 'ls_password').clear()
driver.find_element(By.ID, 'ls_password').send_keys('123456')
driver.find_element(By.XPATH, '/html/body/div[5]/div/div[1]/form/div/div/table/tbody/tr[2]/td[3]/button/em').click()
sleep(3)

# 发帖
driver.find_element(By.XPATH, '//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
driver.find_element(By.ID, 'newspecial').click()
driver.find_element(By.ID, 'subject').clear()
driver.find_element(By.ID, 'subject').send_keys('标题1')
# 嵌套页面
driver.switch_to.frame('e_iframe')
driver.find_element(By.XPATH, '/html/body').clear()
driver.find_element(By.XPATH, '/html/body').send_keys('帖子1')
# 跳出嵌套页面
driver.switch_to.default_content()
driver.find_element(By.ID, 'postsubmit').click()
sleep(3)

# 退出
driver.find_element(By.LINK_TEXT, '退出').click()
sleep(3)

driver.quit()
